package com.meme.editor.event;

import com.meme.editor.EntityObject;



// not a standard event implementation
public class EntityChangedEvent
{
	public static final int ModType_General = 0;
	public static final int ModType_PublicPropertyValuesModified = 1;
	public static final int ModType_PublicPropertyItemsChanged = 2; // for future
	
	public static final int ModType_Removed = 9;
	public static final int ModType_Appended = 10;
	public static final int ModType_IndexModified = 11;	
	public static final int ModType_NameModified = 12;
	
	public static final int ModType_ChildrenRemoved = 16;
	public static final int ModType_ChildrenAppended = 17;
	public static final int ModType_ChildrenIndexesModified = 18;	
	public static final int ModType_ChildrenNamesModified = 19;
	
	
	public static final int ModSource_Child = 0;
	public static final int ModSource_Parent = 1;
	public static final int ModSource_Refer = 2;
	public static final int ModSource_Refed = 3;
	

	EntityObject mEventSource;	
	int mAccumulatedModEvents;


	
	public EntityChangedEvent (EntityObject source)
	{
		mEventSource = source;
		
		reset ();
	}
	
	public EntityObject getSource ()
	{
		return mEventSource;
	}

	public void reset ()
	{
		mAccumulatedModEvents = 0;
	}

	public boolean hasEventsToFire ()
	{
		return mAccumulatedModEvents != 0;
	}

	// 
	public boolean registerModification (int modType)
	{
		if ( ( mAccumulatedModEvents & (1 << modType) ) != 0 )
			return false; // already registered
		
		// register
		mAccumulatedModEvents |= (1 << modType);
		mAccumulatedModEvents |= (1 << ModType_General);
		
		switch (modType)
		{
		case ModType_NameModified:
			mAccumulatedModEvents |= (1 << ModType_PublicPropertyValuesModified);
			break;
		}
		
		return true;
	}

//------------------------------------------------------------------------	
	
	public boolean isRemovedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_Removed) ) != 0;
	}
	
	public boolean isAppendedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_Appended) ) != 0;
	}
	
	public boolean isIndexModifiedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_IndexModified) ) != 0;
	}
	
	public boolean isNameModifiedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_NameModified) ) != 0;
	}
	
//------------------------------------------------------------------------	
	
	public boolean isChildrenNamesModifiedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_ChildrenNamesModified) ) != 0;
	}
	
	public boolean isChildrenIndexesModifiedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_ChildrenIndexesModified) ) != 0;
	}
	
	public boolean isChildrenRemovedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_ChildrenRemoved) ) != 0;
	}
	
	public boolean isChildrenAppendedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_ChildrenAppended) ) != 0;
	}

	public boolean isChildrenListChangedEvent ()
	{
		return isChildrenRemovedEvent () | isChildrenAppendedEvent () | isChildrenIndexesModifiedEvent ();
	}

//------------------------------------------------------------------------	
	
	public boolean isPublicPropertitesModifiedEvent ()
	{
		return (mAccumulatedModEvents & (1 << ModType_PublicPropertyValuesModified) ) != 0;
	}
	


}
